package com.minggo.charmword.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.minggo.charmword.R;

/**
 * 对话框
 * 
 * @author minggo
 * @date 2014-9-28 下午5:50:50
 */
public class WordDialog extends Dialog {

	public static final int UPLOAD_AVATAR_DIALOG = 1;// 上传头像对话框
	public static final int SELECT_LOCAL_PICTURE = 2;//现则本地图片
	public static final int SELECT_CAMERA_PICTURE = 3;//照相
	public static final int LOADING = 4;//加载对话无按钮
	public static final int TWO_BUTTON = 5;//有两个按钮对话框
	public static final int BUTTON_LEFT = 1;
	public static final int BUTTON_RIGHT = 2;
	
	
	private int type;
	private Context context;
	private int theme;
	private String title;
	private OnDialogClickListener onDialogClickListener;
	private String content;

	public WordDialog(Context context, int theme, int type,String title, OnDialogClickListener onDialogClickListener) {
		super(context, theme);
		this.title = title;
		this.context = context;
		this.theme = theme;
		this.onDialogClickListener = onDialogClickListener;
		this.type = type;
	}
	
	public WordDialog(Context context,int theme,int type,String title,String content){
		super(context, theme);
		this.type = type;
		this.title = title;
		this.content = content;
	}
	public WordDialog(Context context,int theme,int type,String title,String content,OnDialogClickListener onDialogClickListener){
		super(context, theme);
		this.type = type;
		this.title = title;
		this.content = content;
		this.onDialogClickListener = onDialogClickListener;
	}
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initDialog();
	}

	private void initDialog() {
		switch (type) {
		case UPLOAD_AVATAR_DIALOG:
			this.setContentView(R.layout.dialog_capture_pop);
			break;
		case LOADING:
			this.setContentView(R.layout.dialog_loading_no_button);
			break;
		case TWO_BUTTON:
			this.setContentView(R.layout.dialog_two_button);
			break;
		default:
			break;

		}
		initUI();
	}
	
	private void initUI(){
		if (type == UPLOAD_AVATAR_DIALOG) {
			((TextView) findViewById(R.id.tv_dialog3_title)).setText(title);
			Button camera = (Button) findViewById(R.id.camera);
			Button garrely = (Button) findViewById(R.id.garrely);
			camera.setOnClickListener(new Button.OnClickListener() {

				public void onClick(View v) {
					onDialogClickListener.onDialogClick(SELECT_CAMERA_PICTURE);
				}
			});
			garrely.setOnClickListener(new Button.OnClickListener() {

				public void onClick(View v) {
					onDialogClickListener.onDialogClick(SELECT_LOCAL_PICTURE);
				}
			});
			
			ImageView dialog_exit = (ImageView) findViewById(R.id.dialog_exit);
			dialog_exit.setOnClickListener(new Button.OnClickListener() {

				public void onClick(View v) {
					dismiss();
				}
			});
		}else if (type == LOADING) {
			((TextView) findViewById(R.id.tv_loading_title)).setText(title);
			((TextView) findViewById(R.id.tv_loading_content)).setText(content);
		}else if (type == TWO_BUTTON) {
			((TextView) findViewById(R.id.tv_loading_title)).setText(title);
			((TextView) findViewById(R.id.tv_loading_content)).setText(content);
			((Button) findViewById(R.id.bt_dialog_left)).setOnClickListener(new Button.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					onDialogClickListener.onDialogClick(BUTTON_LEFT);
				}
			});
			((Button) findViewById(R.id.bt_dialog_right)).setOnClickListener(new Button.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					onDialogClickListener.onDialogClick(BUTTON_RIGHT);
				}
			});
			
		}
	}

	/**
	 * 点击的回调接口
	 * 
	 * @author minggo
	 * @date 2014-2-21 下午5:21:40
	 */
	public interface OnDialogClickListener {
		public void onDialogClick(int state);
	}
}
